package nowcoder_05_27;

//JAVA41 Head and Tail of the Queue
//Students are picked from a group of students to give speeches.
//To be fair, the head and tail of the queue are drawn alternately. Please implement the process of leaving the queue through the program.
//输入描述：
//A group of students' names
//输出描述：
//Print the names of the students at the head and tail of the queue alternately

//示例
//输入：
//Tom Jim Lily Lucy Mary
//输出：
//Tom
//Mary
//Jim
//Lucy
//Lily


import java.util.ArrayDeque;
import java.util.Scanner;

public class Main2 {

    public static void main(String[] args) {
        ArrayDeque deque = new ArrayDeque();

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String name = scanner.next();
            // 初始化队列中的数据
            deque.offerLast(name);
        }

        // write your code here......
        int size = deque.size(); // 这里需要记录起初的队列大小，
        // 因为到后面遍历过程中会不断减小
        for(int i = 0; i < size; i++)
        {
            if(i % 2 == 0)
            {
                System.out.println(deque.pollFirst());
            }else{
                System.out.println(deque.pollLast());
            }
        }

    }

}
